package sctu.edu.java.year2016.team06.chenqiang.day20160530.chapter9_1;

/**
 * Created by XQ on 2016/5/30.
 * 编写java程序，并在类中创建一个成员内部类，通过成员内部类计算1到任意数值的和，并在外部内中测试。
 */

import java.util.Scanner;

public class Calculate {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Please enter the vaule of num!");
        int num = scan.nextInt();
        System.out.println("1到" + num + "的和为：");
       // int s = new Inner().add(num);
       // System.out.println(s);
        System.out.println(Inner.add(num));
    }


    static class Inner {
        static int add(int num) {
            if (num == 1) {
                return 1;
            } else {
                return num + add(num - 1);
            }
        }
    }
}
